#include <iostream>
#include <signal.h>
#include <unistd.h>
#include <vector>
#include <functional>
using namespace std;
typedef function<void()> work;
vector<work> work_group;
void fun1()
{
    cout << "我是一个检查内存碎片的程序" << endl;
}
void fun2()
{
    cout << "我是一个上传任务" << endl;
}
void fun3()
{
    cout << "我是一个下载任务" << endl;
}
void sig_handle(int sig)
{
    cout << "接收到信号：" << sig << " 开始工作" << endl;
    for(auto fun:work_group)
        fun();
    alarm(2);
    //exit(1);
}
int main()
{
    vector<work> group{fun1, fun2, fun3};
    work_group = group;
    signal(SIGALRM, sig_handle);
    alarm(2);
    cout << "run" << endl;
    while (true)
    {
        pause();
        //sleep(1);
    }
    return 0;
}
